package gitlab_hook

import "atomgit.com/openlinksaas-org/proto-gen-go.git/events/events_gitlab"

type PushHook struct {
	ObjectKind        string     `json:"object_kind"`
	Before            string     `json:"before"`
	After             string     `json:"after"`
	Ref               string     `json:"ref"`
	CheckoutSha       string     `json:"checkout_sha"`
	UserId            int64      `json:"user_id"`
	UserName          string     `json:"user_name"`
	UserUsername      string     `json:"user_username"`
	UserEmail         string     `json:"user_email"`
	UserAvatar        string     `json:"user_avatar"`
	ProjectId         int64      `json:"project_id"`
	Project           Project    `json:"Project"`
	Repository        Repository `json:"repository"`
	Commits           []Commit   `json:"commits"`
	TotalCommitsCount int64      `json:"total_commits_count"`
}

func (item *PushHook) ToProtoBuf() *events_gitlab.PushEvent {
	ret := &events_gitlab.PushEvent{
		ObjectKind:        item.ObjectKind,
		Before:            item.Before,
		After:             item.After,
		Ref:               item.Ref,
		CheckoutSha:       item.CheckoutSha,
		UserId:            item.UserId,
		UserName:          item.UserName,
		UserUsername:      item.UserUsername,
		UserEmail:         item.UserEmail,
		UserAvatar:        item.UserAvatar,
		ProjectId:         item.ProjectId,
		Project:           item.Project.ToProtoBuf(),
		Repository:        item.Repository.ToProtoBuf(),
		Commits:           []*events_gitlab.Commit{},
		TotalCommitsCount: item.TotalCommitsCount,
	}
	if item.Commits != nil {
		for _, commit := range item.Commits {
			ret.Commits = append(ret.Commits, commit.ToProtoBuf())
		}
	}
	return ret
}
